package com.shoparc.mvc;

import java.awt.event.KeyEvent;

public class Controller {
	
	protected ViewFrame parent;
	protected int mwheel;
	public boolean mouseDragged;
	
	public Controller(ViewFrame _parent){
		parent = _parent;
		mwheel = 0;
		mouseDragged = false;
	}
	
	
	public void setup(){		
		parent.addMouseWheelListener(new java.awt.event.MouseWheelListener() {
		public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
			mouseWheel(evt.getWheelRotation());
		}
	});

	}
	
	protected void keycontrol(){
	
		if ((parent.keyPressed) && (parent.key == '.')) {
			parent.target.z -= 5;
		}
		if ((parent.keyPressed) && (parent.key == '/')) {
			parent.target.z += 5;
		}
	
	}
	
	protected void mousecontrol(){
		
	}	
	
	protected void camVarUpdate() {

		if ((parent.keyPressed) && (parent.keyCode == KeyEvent.VK_ALT) && (parent.mousePressed)) {
			if ((parent.mouseX - parent.pmouseX) > .5) {
				parent.Ctheta += .03 * Math.abs(parent.mouseX - parent.pmouseX);
			}
			if ((parent.mouseX - parent.pmouseX) < -.5) {
				parent.Ctheta -= .03 * Math.abs(parent.mouseX - parent.pmouseX);
			}
			if ((parent.mouseY - parent.pmouseY) > .5) {
				parent.Czeta += .03 * Math.abs(parent.mouseY - parent.pmouseY);
			}
			if ((parent.mouseY - parent.pmouseY) < -.5) {
				parent.Czeta -= .03 * Math.abs(parent.mouseY - parent.pmouseY);
			}
			if (parent.Czeta > Math.PI / 2)
				parent.Czeta = (float) (Math.PI / 2 - .001);
			if (parent.Czeta < -Math.PI / 2)
				parent.Czeta = (float) (-Math.PI / 2 + .001);

		}
		if (mwheel > 0) {
			parent.zoom += 20;
		}
		if (mwheel < 0) {
			parent.zoom -= 20;
		}
		mwheel = 0;
	}
	
	protected void mouseWheel(int delta) {
		mwheel = delta;

	}
	
	public void mouseDragged() {
		mouseDragged = true;
	}



}
